<?php

class Ext_Image_Show_Adapter_Base extends Ext_Image_Show_Abstract
{
    public function __construct()
    {
    }
    
    public function build($imageId)
    {
        $image = App_Model_DbTable_Image::getInstance()->getRowById($imageId);
        if(!$image){
            return "";
        }
        
        $this->source = $this->_buildUrl($image['source']);
        $this->big    = $this->_buildUrl($image['big']);
        $this->middle = $this->_buildUrl($image['middle']);
        $this->small  = $this->_buildUrl($image['small']);
        $this->thumb  = $this->_buildUrl($image['thumb']);
    }
    
    private function _buildUrl($imageBaseId)
    {
        if(!$imageBaseId){
            return "";
        }
        $imageBase = App_Model_DbTable_Image_Base::getInstance()->getRowById($imageBaseId);
        if(!$imageBase){
            return "";
        }
        $path     = $imageBase['path'];
        $fileName = $imageBase['fileName'];
        
        if (substr(PHP_OS, 0, 3) == 'WIN'){
            $path = str_replace(DIRECTORY_SEPARATOR, "/", $path);
        }
        
        $config = Ext_Config::getInstance()->getConfig('image');
        
        $url = '';
        if(isset($config->storage->base->url)){
            $url .= rtrim($config->storage->base->url, "/");
        }
        
        $url .= "/".$path.'/'.$fileName;
        
        return $url;
    }
}
